<?php
	require_once './Tool/DB/SqlDBManager.class.php';
	require_once './Tool/Common/PrepareInput.php';
	$sqlDBManager = new SqlDBManager();
	
	if(!empty($_SESSION['selectedBackDate'])){
        $date=$_SESSION['selectedBackDate']; 
    }else{
        $date=date('Y-m-d', time());
    }
	$userCentreName = $_SESSION["centreName"];
		
	$sql ="SELECT attendancerecord.NRIC, client.CustomerName, centre.CentreName, 
		attendancerecord.SignInTimeStamp, attendancerecord.SignOutTimeStamp, 
		attendancerecord.Status 
		FROM attendancerecord, client, centre 
		WHERE DATE(SignInTimeStamp)='$date' 
		AND attendancerecord.NRIC = client.NRIC 
		AND attendancerecord.CentreId = centre.CentreId 
		AND centre.CentreName = '$userCentreName'";
	
	$res=$sqlDBManager->queryRows($sql);

	echo "<table class='tablereport' id='tblAttendance' border='5'  valign='top'><tr >
	<th name='Number'>
	Number
	</th>
	<th name='NRIC'>
	NRIC
	</th>
	<th name='Customer Name'>
	Customer Name
	</th>
	<th name='CentreName'>
	Centre Name
	</th>
	<th name='Date'>
	Date
	</th>
	<th name='TimeIn' >
	Time In
	</th>
	<th name='TimeOut'>
	Time Out
	</th>
	<th name='Status'>
	Status
	</th>
	</tr>";
	    $count=1;
		for($i=0;$i<count($res);$i++){
	        echo"<tr>
			<td >
			" . $count . "
			</td >
			<td >
			" . $res[$i]['NRIC'] . "
			</td >
			<td >
			" . $res[$i]['CustomerName'] . "
			</td >
			<td >
			" . $res[$i]['CentreName'] . "
			</td >";
				$signin = strtotime($res[$i]['SignInTimeStamp']);
				$signintime = date('j F, Y', $signin);
				echo "
			<td >
			" . $signintime . "
			</td>
			";
				$signin = strtotime($res[$i]['SignInTimeStamp']);
				$signintime = date('H:i:s', $signin);
				echo"<td >
			" . $signintime . "
			</td>";
				if ($res[$i]['SignOutTimeStamp'] == '0000-00-00 00:00:00') {
					echo "
				<td >
				</td>
				<td>
				<form method='POST'><input class='signoutbutton' id='signout" . $count . "'type='submit' name='signout" . $count . "'value='Sign Out' size='10' maxlength='9' align='center' onClick='this.style.display = 'none';signoutattendance(this.id)'/></form>
				</td>
				";
				} else {
					$signout = strtotime($res[$i]['SignOutTimeStamp']);
					$signouttime = date('H:i:s', $signout);
					echo"
				<td >
				" . $signouttime . "
				</td>
				<td>
				" . $res[$i]['Status'] . "
				</td >
				";
				} echo"
				

			</tr>"
				;
				$count++;
	    }
	    echo "</table>";
	    $count--;
	    echo "Total number of elderly attended: " . $count . ".";

?>